import { defineStore } from 'pinia';
import {store} from './index'

const userAccountStore = defineStore('main', {
    state: () => {
      return {
        logon: false,
        userIdentity: null,
        authenticated: false
      }
    },
    getters: {
      account: state => state.userIdentity,
    },
    actions: {
      authenticate(promise) {
        this.logon = promise;
      },
      setAuthentication(identity) {
        this.userIdentity = identity;
        this.authenticated = true;
        this.logon = null;
      },
      logout() {
        this.userIdentity = null;
        this.authenticated = false;
        this.logon = null;
      },
    }
  })

export const useUserOut = () => {
    return userAccountStore(store)
}
  